package edu.pku.sei.mte.exceptions.handler;

import edu.pku.sei.mte.exceptions.ExceptionRegistry;
import edu.pku.sei.mte.exceptions.MultiValueBindingsException;
import edu.pku.sei.mte.exceptions.TException;
import edu.pku.sei.mte.modification.ModelModificationManager;


public class MTExceptionHandler {
	
	public boolean catchExpressionException(TException expr){
		return true;
	}
	public boolean catchStructureException(TException expr){
		return true;
	}
	public boolean catchUserDefinedException(TException expr){
		return true;
	}
	
	protected ExceptionRegistry reg = initialExceptionRegistry();
	
	protected static ExceptionRegistry initialExceptionRegistry(){
		ExceptionRegistry r = new ExceptionRegistry();
		r.addExceptionHandler(MultiValueBindingsException.class, new DefaultMultiValueBindingsExceptionHandler());
		return r;
	}
	
	public void registerExceptions(ExceptionRegistry er){
		if(er == null)
			return;
		reg.addExceptionRegistry(er);
	}
	
	protected ExceptionHandler getExceptionHandler(Exception e){
		ExceptionHandler handler = reg.getExceptionHandler(e);
		if(handler == null)
			handler = new DefaultExceptionHandler();
		return handler;
	}
	public boolean catchSemanticException(TException ex) throws Exception {
		ExceptionHandler handler = getExceptionHandler(ex);
		handler.handle(ex);
		return false;
	}
	
	public void checkUserDefinedException() throws Exception {
		
	}
}
